package com.gitee.jiaojinxin.oauth2.client1.util;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;

public class AuthenticationUtil {
    private AuthenticationUtil(){}

    public static Authentication authentication(){
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static String tokenVal(){
        Object obj = authentication().getDetails();
        if (obj instanceof OAuth2AuthenticationDetails) {
            return ((OAuth2AuthenticationDetails) obj).getTokenValue();
        }
        return "";
    }
}
